cmake_minimum_required(VERSION 3.29)

project(my-algorithms)

# 设置 C++ 标准
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
    message(">> using Clang")
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
    message(">> using GCC")
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
    message(">> using Intel C++")
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
    message(">> using Visual Studio C++")
    add_compile_options("/utf-8")
else()
    message(">> unknown compiler.")
endif()

# 第三方库
# 组件 Eigen
set(Eigen3_DIR $ENV{Eigen_DIR})
find_package(Eigen3 3 REQUIRED)
include_directories(${EIGEN3_INCLUDE_DIRS})
link_directories(${EIGEN3_LIBRARY_DIRS})

# 项目源代码
include_directories(src)

macro(AddFileDirectory dir)
    file(GLOB SRC ${dir}/*.*)
    set(LOCAL_SRC_ALL ${LOCAL_SRC_ALL} ${SRC})
endmacro()

if (CMAKE_SYSTEM_NAME MATCHES "Linux")

elseif (CMAKE_SYSTEM_NAME MATCHES "Windows")

endif()

AddFileDirectory(src)
AddFileDirectory(src/filter)


# 生成程序
set(BUILD_SHARED_LIBS ON)
add_library(${PROJECT_NAME} ${LOCAL_SRC_ALL})
target_link_libraries(${PROJECT_NAME} PRIVATE
        ${EIGEN_LIBRARY_DIRS})

if (CMAKE_SYSTEM_NAME MATCHES "Linux")
    set_target_properties(${PROJECT_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/build/bin)
    set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME "${PROJECT_NAME}.bin")
elseif (CMAKE_SYSTEM_NAME MATCHES "Windows" AND CMAKE_BUILD_TYPE STREQUAL "Debug")
    set_target_properties(${PROJECT_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/build/bin/Debug)
    set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME ${PROJECT_NAME})
elseif (CMAKE_SYSTEM_NAME MATCHES "Windows" AND CMAKE_BUILD_TYPE STREQUAL "Release")
    set_target_properties(${PROJECT_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/build/bin/Release)
    set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME ${PROJECT_NAME})
endif ()

option(ENABLE_TESTS "Build the test" ON)
if (ENABLE_TESTS)
	# 启用测试
    enable_testing()  
    add_subdirectory(test)  
endif ()

